﻿using com.nm.Attributes;
using com.nm.library.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NHibernateVertica
{
    public class GetTableData<T> where T : new()
    {

        public VerticaDataHelper Helper { get; set; } = new VerticaDataHelper();
        /// <summary>
        /// 根据表名查询获取数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="TableName">要查询的表名</param>
        /// <param name="Parm">需要查询的参数</param>
        /// <param name="where">查询条件 and 开始,默认</param> 
        /// <param name="Order">排序</param>
        /// <param name="Group">分组</param>
        ///  Writer：GavinGu
        ///  Create Date：2017-11-16
        /// <returns>对应的Ilist，需要做toList处理</returns>
        public IList<T> GetDataByTableName(
            [ParamDescription("表名")] string TableName,
            [ParamDescription("要查询的参数，默认为全部(*)")] string Parm = "*",
            [ParamDescription("查询条件")] string where = "",
            [ParamDescription("排序")] string Order = "",
            [ParamDescription("分组")] string Group = ""
          )
        {
            //if (!string.IsNullOrWhiteSpace(where))
            //    where = $"AND  CompanyID='{UserInfo.UserCompanyId}'";
            string sql = $@"SELECT {Parm}  FROM {TableName} WHERE 1=1 {where} {Group} {Order}";
            var cmd = Helper.GetSqlStringCommand(sql);
            var dt = Helper.ExecuteDataTable(cmd);
            return ModelConvertHelper<T>.ConvertToModel(dt);
        }


    }
}
